import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


# 启动Edge浏览器
driver = webdriver.Chrome()

# 打开页面
driver.get("file:///F:/TestProject/register.html")

# 定位到下拉选择框
select_element = driver.find_element(By.ID, "selectA")

# 使用Select类操作下拉选择框
select = Select(select_element)

# 通过索引选择选项
select.select_by_index(1)  # 选择上海
time.sleep(3)

# 通过值选择选项
select.select_by_value("gz")  # 选择广州
time.sleep(3)

# 通过可见文本选择选项
select.select_by_visible_text("深圳")  # 选择深圳
time.sleep(3)

# 关闭浏览器
driver.quit()